<template>
	<div class="count">
		<h1>当前求和为：{{sum}}</h1>
		<h3>当前求和放大10倍后：{{bigSum}}</h3>
		<h3>学校名称：{{school}}</h3>
		<h3>学校地址：{{address}}</h3>
		<h3>完整地址：{{fullAddress}}</h3>
		<h3>所学学科：{{subject}}</h3>
		<select v-model.number="n">
			<option value="1">1</option>
			<option value="2">2</option>
			<option value="3">3</option>
		</select>
		<button @click="JIA(n)">+</button>
		<button @click="JIAN(n)">-</button>
		<button @click="jiaOdd(n)">当前求和为奇数再+</button>
		<button @click="jiaWait(n)">等一等再+</button>
		<button @click="jiaServer">问问服务器再+</button>
	</div>
</template>

<script>
	import {mapState,mapGetters,mapActions,mapMutations} from 'vuex'
	export default {
		name:'Count',
		data() {
			return {
				n:1 //用户选择的数字
			}
		},
		computed:{
			...mapState(['sum','school','address','subject']),
			...mapGetters(['bigSum','fullAddress'])
		},
		methods:{
			// 程序员辛辛苦苦，自己写回调
			//#region 
			/* 
				//加
				increment(){
					//联系对应的mutation函数，触发JIA（即：直接联系厨师）
					this.$store.commit('JIA',this.n)
				},
				//减
				decrement(){
					//联系对应的mutation函数，触发JIAN（即：直接联系厨师）
					this.$store.commit('JIAN',this.n)
				}, 
			*/
			//#endregion
			
			// 第一种写法
			// ...mapMutations({increment:'JIA',decrement:'JIAN'}),

			// 第二种写法
			...mapMutations(['JIA','JIAN']),
			...mapActions(['jiaOdd','jiaWait','jiaServer'])
		},
	}
</script>

<style scoped>
	.count{
		background-color: skyblue;
		padding: 20px;
	}
	button{
		margin-left: 10px;
	}
</style>